package com.zbkj.crmeb.merchant.admin.controller;


import com.crmeb.core.common.CommonResult;
import com.utils.CrmebUtil;
import com.zbkj.crmeb.agent.request.AgentAccountCenterRequest;
import com.zbkj.crmeb.agent.service.AgentAccountService;
import com.zbkj.crmeb.agent.service.AgentService;
import com.zbkj.crmeb.agent.vo.AgentVo;
import com.zbkj.crmeb.chant.response.AccountCenterResponse;
import com.zbkj.crmeb.finance.request.UserRechargeRequest;
import com.zbkj.crmeb.system.service.SystemAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 服务商资金账户表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-02-15
 */
@RestController
@RequestMapping("/api/admin/mer/agent-account")
@Api(tags = "服务商-服务商账户")
public class MerAgentAccountController {

    @Autowired
    AgentAccountService agentAccountService;
    @Autowired
    SystemAdminService systemAdminService;
    @Autowired
    AgentService agentService;

    @ApiOperation(value = "服务商提现")
    @PostMapping("/withdraw/offline")
    public CommonResult<String> offlineWithdraw(@RequestBody UserRechargeRequest userRechargeRequest, HttpServletRequest request){
        return agentAccountService.offlineWithdrawApply(systemAdminService.getAdminAgentId(), userRechargeRequest.getPrice(), CrmebUtil.getClientIp(request)) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "服务商账户中心")
    @GetMapping(value = "/account/center")
    public CommonResult<AccountCenterResponse> accountCenter(@Validated AgentAccountCenterRequest request){
        request.setAgentId(systemAdminService.getAdminAgentId());
        return CommonResult.success(agentAccountService.agentAccountCenter(request));
    }

    @ApiOperation(value = "当前服务商详情")
    @GetMapping(value = "/info")
    public CommonResult<AgentVo> getAgentInfo(){
        return agentService.getAgentById(systemAdminService.getAdminAgentId());
    }

    @ApiOperation(value = "服务商账户中心查看详情")
    @GetMapping(value = "/account/info/{id}")
    public CommonResult<Object> accountInfo(@PathVariable("id") Integer id){
        return CommonResult.success(agentAccountService.agentAccountInfo(id));
    }

}

